<!--
 * @Author: ZhaoZhiqi
 * @Date: 2022-08-29 16:05:20
 * @LastEditors: ZhaoZhiqi
 * @LastEditTime: 2022-12-13 19:57:39
 * @Description: 文章列表
 * @FilePath: \tuanfeng-mini\src\pages\articles.vue
-->
<template>
    <div class="container">
        <template v-if="!loading && list.length">
            <div class="item" v-for="item in list" @click="toDetail(item)">
                <div class="title">{{item.title}}</div>
                <div class="time">{{item.publishTimeStr}}</div>
            </div>
        </template>
        <Empty v-if="!loading && !list.length"></Empty>
    </div>
</template>
<script>
import Empty from "../components/Empty.vue";
import { getLatestArtAPI, getArtByArtCodeAPI } from "../api/article";
export default {
    components: { Empty },
    data() {
        return {
            loading: false,
            list: [],
            title: ""
        };
    },
    onShareAppMessage(){},
    onLoad(options) {
        let { id, title } = options;
        this.title = title;

        wx.setNavigationBarTitle({title})

        this.loading = true;
        wx.showLoading({
            title: "加载中...",
        });
        getArtByArtCodeAPI(id).then((res) => {
            this.list = res.data;
            wx.hideLoading();
            this.loading = false;
        });
    },
    methods: {
        toDetail(item) {
            this.$u.route({
                url: "pages/article_detail",
                params: {
                    id: item.id,
                    title: this.title
                },
            });
        },
    },
};
</script>
<style scoped lang="scss">
@import "../assets/scss/common.scss";

.container {
    min-height: 100vh;
    background-color: #fff;
    box-sizing: border-box;
    padding: 5px 15px;
    .item {
        border-bottom: 1px solid #efefef;
        padding: 10px 5px;
        &:last-child {
            border: none;
        }
        .title {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            overflow: hidden;
            margin-bottom: 5px;
            color: #0c92ff;
        }
        .time {
            color: $color_secondary-text;
        }
    }
}
</style>
